package com.aaa.three.service.impl;

import com.aaa.three.entity.*;
import com.aaa.three.mapper.DoctorMapper;
import com.aaa.three.pojo.domain.AdminInfo;
import com.aaa.three.pojo.domain.UserEmp;
import com.aaa.three.result.AjaxResult;
import com.aaa.three.service.DoctorService;
import com.aaa.three.sysconst.LoginConst;
import com.aaa.three.sysconst.UserConst;
import com.aaa.three.util.QueryDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;

/**
 * @PACKAGE_NAME: com.aaa.three.service.impl
 * @NAME: DoctorServiceImpl
 * @USER: Tprairie
 * @DATE: 2022/2/17
 * @PROJECT_NAME: three
 */
@Service
public class DoctorServiceImpl implements DoctorService {
    @Autowired
    private DoctorMapper doctorMapper;
    @Autowired
    private HttpSession session;

    @Override
    public AjaxResult listDate() {
        String query = QueryDate.query(0);
        List<AddDate> addDate=doctorMapper.listDate(query);
        return AjaxResult.success(addDate);
    }

    @Override
    public AjaxResult listTwoSchedule(Doctor doctor) {
            AdminInfo attribute = (AdminInfo) session.getAttribute(LoginConst.EMP_IN_SESSION);
            Integer a = attribute.getId();
            doctor.setAid(a);
            String query = QueryDate.query(0);
            doctor.setQuerDate(query);
            List<DoctorList> doctorLists=doctorMapper.listTwoSchedule(doctor);
            Integer sum = doctorLists.size();
            HashMap<Object, Object> map = new HashMap<>();
            map.put("doctorLists",doctorLists);
            map.put("twosum",sum);
            return AjaxResult.success(map);
    }

    @Override
    public AjaxResult listOneSchedule(Doctor doctor) {
        AdminInfo attribute = (AdminInfo) session.getAttribute(LoginConst.EMP_IN_SESSION);
        Integer a = attribute.getId();
        doctor.setAid(a);
        String query = QueryDate.query(0);
        doctor.setQuerDate(query);
        List<Registered> registeredList=doctorMapper.listOneSchedule(doctor);
        int size = registeredList.size();
        HashMap<Object, Object> map = new HashMap<>();
        map.put("listall",registeredList);
        map.put("onesum",size);
        return AjaxResult.success(map);
    }

    @Override
    public AjaxResult updateRegistration(Registered registered) {
        Integer i=doctorMapper.updateRegistration(registered);
        if(i>0){
            return AjaxResult.success();
        }
        return AjaxResult.fail("处理失败");
    }
}
